package com.database;

import com.databases.dao.ClothesMapper;
import com.fullstack.bean.Clothes;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class asd {

    public static void main(String[] args) throws IOException {
        List<Clothes> clothes= null;

        try {
            //执行Mybatis 存取数据库
            String resource = "SqlMapConfig.xml";           //绑定主体.xml

            //对SqlMapConfig.xml读取并解析
            InputStream inputStream = Resources.getResourceAsStream(resource);

            //获取会话工厂SqlSessionFactory
            SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

            //SqlSession主要用于对数据库的操作
            SqlSession session =  sessionFactory.openSession();     //获取数据库执行对象

            ClothesMapper mapper = session.getMapper(ClothesMapper.class);//接口名.class 获取对象   反射机制，通过接口，执行.xml里sql语句

            clothes = mapper.select_allmen("男");



            session.commit();     //增删改需要执行事件 查询不用
            session.close();      //关闭
            inputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        for(Clothes c : clothes){
            System.out.println(c.getId());
        }
    }
}
